<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>更改口令</title>
    <link href="../../../css/sys.css" type="text/css" rel="stylesheet"/>
    <style>
        .updpwd {
            background-color: #2ae;
        }

        .login_btn {
            background-color: #9be;
            width: 99px;
            font-size: 14px;
            font-family: 微软雅黑;
        }

        .upd_pwd_msg {
            font-size: 14px;
            text-align: right;
        }
    </style>
    <script type="text/javascript">
        function closeWindow(flag) {
            if (flag == 'change') {
                //alert('修改完毕');
            }
            parent.window.opener = null;
            parent.close();
        }
    </script>
</head>

<body class="updpwd">
<form action="/crm2/staff/staffAction_editPassword.action" method="post">
    <table style="width: 200px">
        <tr>
            <td colspan="2">
                <span id="msgId" class="upd_pwd_msg"> </span>
            </td>
        </tr>
        <tr>
            <td>原始密码：</td>
            <td><input type="password" name="oldPassword" value="" id="oldPwd"/></td>
        </tr>
        <tr>
            <td>新&nbsp;密&nbsp;码：</td>
            <td><input type="password" name="newPassword" value="" id="newpwd1"/></td>
        </tr>
        <tr>
            <td>确认密码：</td>
            <td><input type="password" name="reNewPassword" value="" id="newpwd2"/></td>
        </tr>
        <tr>
            <td colspan="2">
                <%--<input type="button" value="修改" class="login_btn" id="change" onclick="changePwd()"/>--%>
                <button type="reset" value="修改" class="login_btn" onclick="changePwd()">修改</button>
                <button type="reset" value="关闭" class="login_btn">关闭</button>

            </td>
        </tr>
    </table>
</form>

<script src="../../../js/jquery-3.2.1.js"></script>

<script>
    function changePwd() {
        var oldPwd = $("#oldPwd").val();
        var newPwd1 = $("#newpwd1").val();
        var newPwd2 = $("#newpwd2").val();
        if (oldPwd === null || oldPwd === "" || newPwd1 === null || newPwd1 === ""||
                newPwd2 === null || newPwd2 === "") {
            alert("输入不能为空");
        } else {
            if (!newPwd1 === newPwd2) {
                alert("两次密码不一致")
            } else {
                $.ajax({
                    url: "/changePwd",
                    data: {
                        oldPwd: oldPwd,
                        newPwd: newPwd1
                    },
                    success: function (result) {
                        var msg = result.msg;
                        if (msg === "更改成功") {
                            alert("更改成功");
                            window.location.href = "/logout";
                        } else if (msg === "原密码不正确") {
                            alert("原密码不正确")
                        }
                    },
                    error: function () {
                        alert("遇到了未知的错误")
                    }
                })
            }
        }
    }
</script>

</body>
</html>
